# -*- coding: utf-8 -*-

'''eof
name:国籍不符
code:Region_NotMatch
tableName:
columnName:
groups:准入>企业业务信息校验
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import datetime

reload(sys)
sys.setdefaultencoding('utf-8')
'''
ratingRequest:中提取申请人身份证号码：legalPersonIdCard
解析身份证号前两位 
如果在area里面 返回为1
如果不再area里面 返回为0
'''

def Region_NotMatch():
    null_type_list = ['', None, 'null', 'Null', 'NULL', '/']
    area={"11":"北京","12":"天津","13":"河北","14":"山西","15":"内蒙古","21":"辽宁",
          "22":"吉林","23":"黑龙江","31":"上海","32":"江苏","33":"浙江","34":"安徽",
          "35":"福建","36":"江西","37":"山东","41":"河南","42":"湖北","43":"湖南",
          "44":"广东","45":"广西","46":"海南","50":"重庆","51":"四川","52":"贵州",
          "53":"云南","54":"西藏","61":"陕西","62":"甘肃","63":"青海","64":"宁夏",
          "65":"新疆"}

    try:
        if ratingRequest['legalPersonIdCard'] not in null_type_list :
            if len(ratingRequest['legalPersonIdCard']) == 18:

                area_code = ratingRequest['legalPersonIdCard'][0:2]

                if area.has_key(area_code):
                    return 1
                else:
                    return 0
            else:
                return 0
        else:
            return u'缺失值'
    except:
        return u'缺失值'

result = Region_NotMatch()